﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Extentions;

namespace TrainingReminderSystem.Model
{
    /// <summary>
    /// 配置类
    /// </summary>
    public static class SysConfig
    {
        /// <summary>
        /// 变量
        /// </summary>
        private static string _dbConnectionString;

        /// <summary>
        /// 连接字符串
        /// </summary>
        public static string DbConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_dbConnectionString)) _dbConnectionString = ConfigurationHelper.DbConnectionString;
                return _dbConnectionString;
            }
            set { _dbConnectionString = value; }
        }

        /// <summary>
        /// 项目名称
        /// </summary>
        public static string ProjectName
        {
            get
            {
                return ConfigurationHelper.ProjectName;
            }
        }

        /// <summary>
        /// 是否使用https
        /// </summary>
        public static bool UseHttps
        {
            get
            {
                return ConfigurationHelper.UseHttps;
            }
        }

        /// <summary>
        /// 是否需要验证码
        /// </summary>
        public static bool NeedCaptcha
        {
            get
            {
                return ConfigurationHelper.GetConnectionString("NeedCaptcha").ExToBool();
            }
        }

        /// <summary>
        /// 验证码长度
        /// </summary>
        public static int CaptchaLength
        {
            get
            {
                int val = ConfigurationHelper.GetConnectionString("CaptchaLength").ExToInt32();
                if (val == 0) val = 4;
                return val;
            }
        }

        /// <summary>
        /// 微信开放平台参数
        /// </summary>
        public static bool CheckPublish { get; } = ConfigurationHelper.GetConnectionString("CheckPublish").ExToBool();

        /// <summary>
        /// 开放平台配置信息
        /// </summary>
        public static WxOpen WxOpen { get; } = WxOpen.Instance;

        /// <summary>
        /// 枚举生成的js缓存文件到开发目标目录去
        /// </summary>
        public static string EnumJsPath { get; } = ConfigurationHelper.GetConnectionString("EnumJsPath");

        /// <summary>
        /// 启动项目
        /// </summary>
        public static EnumRunProject EnumRunProject
        {
            get;
            set;
        }

        #region WebSocket端口

        /// <summary>
        /// 是否使用https
        /// </summary>
        public static bool Wss
        {
            get
            {
                return ConfigurationHelper.Wss;
            }
        }

        private static int _webSocketPortChat = 0;

        /// <summary>
        /// WebSocket端口号 没配置默认为0,不开启
        /// </summary>
        public static int WebSocketPortChat
        {
            get
            {
                if (_webSocketPortChat > 0) return _webSocketPortChat;
                _webSocketPortChat = ConfigurationHelper.GetConnectionString("WebSocketPortChat").ExToInt32();
                if (_webSocketPortChat <= 0) _webSocketPortChat = 0;
                return _webSocketPortChat;
            }
        }

        #region 证书

        public static string Pfx { get; } = ConfigurationHelper.GetConnectionString("Pfx");

        public static string PfxPwd { get; } = ConfigurationHelper.GetConnectionString("PfxPwd");

        #endregion

        #endregion

        /// <summary>
        /// 自动间隔更新时间
        /// </summary>
        public static int AutoIntervalTime
        {
            get
            {
                return ConfigurationHelper.GetConnectionString("AutoIntervalTime").ExToInt32();
            }
        }

        public static bool ProxyEnable
        {
            get
            {
                return ConfigurationHelper.GetConnectionString("ProxyEnable").ExToBool();
            }
        }

        public static string ProxyIP
        {
            get
            {
                return ConfigurationHelper.GetConnectionString("ProxyIP");
            }
        }

        public static int ProxyPort
        {
            get
            {
                return ConfigurationHelper.GetConnectionString("ProxyPort").ExToInt32();
            }
        }

        public static string ProxyUID
        {
            get
            {
                return ConfigurationHelper.GetConnectionString("ProxyUID");
            }
        }

        public static string ProxyPwd
        {
            get
            {
                return ConfigurationHelper.GetConnectionString("ProxyPwd");
            }
        }
    }
}
